using System;
using System.Collections.Generic;
using System.Text;
using GoogleTranslator;

namespace GapiTranslator.Test
{
	class Program
	{
		static void Main(string[] args) {
			string toTranslate = "";
			Language sourceLanguage;
			Language targetLanguage;
			GAPITranslator gapiTranslator = new GoogleTranslator.GAPITranslator();
			TranslationResult result;

			System.Console.WriteLine("Ingrese el texto a traducir:");
			System.Console.Write(">> ");
			toTranslate = System.Console.ReadLine();

			System.Console.WriteLine("\nIngrese el idioma de origen (X si desea autodetectar):");
			System.Console.Write(">> ");
			string sLan = System.Console.ReadLine();
			sourceLanguage = GetLanguage(sLan);

			System.Console.WriteLine("\nIngrese el idioma de destino:");
			System.Console.Write(">> ");
			string tLan = System.Console.ReadLine();
			targetLanguage = GetLanguage(tLan);

			string translatedString = "";

			if (sLan.Equals("X")) {
				result = gapiTranslator.Translate(toTranslate, targetLanguage);
			} else {
				result = gapiTranslator.Translate(toTranslate, targetLanguage, sourceLanguage);
			}
			translatedString = result.ToString();

			System.Console.WriteLine("\nResultado de traduccion: ");
			System.Console.WriteLine(translatedString);

			System.Console.WriteLine("\nPresione una tecla para finalizar...");
			System.Console.ReadKey(true);
		}

		private static Language GetLanguage(string lanName) {
			return Language.FindLanguage(lanName);
		}
	}
}
